#encoding=utf8
'''
Created on 2012-10-17

@author: Administrator
'''
from Processor import Processor
from pub import Func;
from pub.Config import Config;
from models import ReleaseModel;

class SVCClass(Processor):
    '''
    指令：SVC (software verson check)
    备注：检测软件版本
    格式：c-s:Cmd#cmdID#userId#version
     s-c:Cmd#cmdID#version#updateTime#updateDesc#updataUrl#result
    '''
    def __init__(self):
        Processor.__init__(self);
        self.__userId = 0;
        self.__version="0.0.0";

        
    def dataValidtor(self, cmdContent):
        if not cmdContent:
            return False;
        paraLen = len(cmdContent);
        if paraLen == 2:      
            self.__userId = Func.toInt(cmdContent[0]);
            self.__version = Func.toStr(cmdContent[1],"0.0.0");        
            return True;        
        return False;
    def outData(self,):
        releaseM=ReleaseModel();
        release=releaseM.getLastRelease();
        sendData=[];
        if not release:
            sendData.append(self.__version);
            sendData.append("");
            sendData.append("");
            sendData.append("");
            sendData.append(0);
        else:
            sendData.append(release.get_release_version());
            sendData.append(release.get_releasetime());
            sendData.append(release.get_release_log());
            sendData.append(release.get_download_url());
            sendData.append(release.get_force_update());
        
        Func.sendMsgStr(self._sockObj, self.setPackage(sendData));
        return True;
            
            
    
       
